const BASE_URL = 'https://qinchenju.com/homemaking/v1'

class JSRequest {
  constructor(baseURL) {
    this.baseURL = baseURL
  }
  request(options) {
    wx.showLoading({
      title: '加载中'
    })
    const {
      url
    } = options
    return new Promise((resolve, reject) => {
      wx.request({
        ...options,
        url: this.baseURL + url,
        success: (res) => {
          wx.hideLoading()
          resolve(res.data)
        },
        fail: (err) => {
          wx.hideLoading()
          console.log("err:", err);
        }
      })
    })
  }
  get(options) {
    return this.request({
      ...options,
      method: "get"
    })
  }
  post(options) {
    return this.request({
      ...options,
      method: "post"
    })
  }
}

export const jsRequest = new JSRequest(BASE_URL)